package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class ParamsProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static ParamsProduction instance = new ParamsProduction();

    public static ParamsProduction getInstance() {
        return instance;
    }


    /**
     * Regra: params : valor (',' valor)*;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!ValorProduction.getInstance().analyze(st, et)) {
            return false;
        }

        while (basicParse(st, TokenClass.DELIMITER_COMMA)) {
            if (!ValorProduction.getInstance().analyze(st, et)) {
                return skipUntilSynchronize(st, et, "Erro na passagem de parametros");
            }
        }

        return true;
    }

    @Override
    protected void populateFirst() {
        //from valor first
        first.add(TokenClass.OPERATOR_NOT);
        first.add(TokenClass.DELIMITER_OPENING_PARENTHESIS);
        first.add(TokenClass.NUMERIC);
        first.add(TokenClass.NUMERIC_REAL);
        first.add(TokenClass.KEYWORD_VERDADEIRO);
        first.add(TokenClass.KEYWORD_FALSO);
        first.add(TokenClass.IDENTIFIER);
        this.first.add(TokenClass.OPERATOR_PLUS);
        this.first.add(TokenClass.OPERATOR_MINUS);
        first.add(TokenClass.OPERATOR_INCREMENT);
        first.add(TokenClass.OPERATOR_DECREMENT);
        this.first.add(TokenClass.KEYWORD_CAST);
        first.add(TokenClass.KEYWORD_STRING);
        first.add(TokenClass.KEYWORD_CARACTERE);
    }

    @Override
    protected void populateFollow() {
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_CLOSING_PARENTHESIS);
    }
}
